Page({
  data:{
    schema:[
      {
        label:'客服链接',
        prop:'url',
        type:'text',
      },
      {
        label:'企业ID',
        prop:'corpId',
        type:'text',
      },
      {
        label:'是否发送小程序气泡消息',
        prop:'showMessageCard',
        type:'switch',
      },
      {
        label:'气泡消息标题',
        prop:'sendMessageTitle',
        type:'text',
      },
      {
        label:'气泡消息小程序路径',
        prop:'sendMessagePath',
        type:'text',
      },
      {
        label:'气泡消息图片',
        prop:'sendMessageImg',
        type:'text',
      }
    ],
    title:'微信客服',
    zh:'',
    formData:{
      url:'1',
      corpId:'2',
      showMessageCard:true,
      sendMessageTitle:'3',
      sendMessagePath:'4',
      sendMessageImg:'5'
    },
    result:''
  },
  onLoad(options){
    this.setData({
      title: options.title,
      zh:options.zh
    })
  },
  getFormData(e){
    this.setData({
      'schema[3].hidden':!e.detail.formData.showMessageCard,
      'schema[4].hidden':!e.detail.formData.showMessageCard
    })
  },
  handleContact (e) {
    let {
      url,
      corpId,
      showMessageCard,
      sendMessageTitle,
      sendMessagePath,
      sendMessageImg
    } = this.data.formData
    let tt = this
    wx.openCustomerServiceChat({
      extInfo:{
        url
      },
      corpId,
      showMessageCard,
      sendMessageTitle,
      sendMessagePath,
      sendMessageImg,
      complete:(e)=>{
        tt.setData({
          result:e
        })
      }
    })
  }
})
